<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge chrome=1"/>
    <meta name="viewport"
          content="width=device-width initial-scale=1.0 minimum-scale=1.0 maximum-scale=1.0 user-scalable=no"/>
    <meta name="format-detection" content="telephone=no email=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <title>Title</title>
</head>
<body>
<!--构造函数模式-->
<!--小明 今年18岁 性别男 有男朋友 男朋友会说话 说什么自己定-->
<!--工厂模式-->
<!--造一辆车 出厂 （合格证/建议零售价/说明书）-->
<script type="text/javascript">
    //构造函数,初始化对象
    //this关键字是一个指针，代表当前的实例化对象
    function Person(name,age,sex){
        this.name = name;
        this.age = age;
        this.sex = sex;
        this.boy = boy;
        this.sayHi= sayHi;
    }
    function boy(){
        alert(this.name+"男朋友");
    }
    function sayHi(){
        alert(this.name+"你好");
    }
    var person1 = new Person("小明",18,"男");//实例化一个对象，this代表person1
    person1.boy();
    person1.sayHi();



    function run1() {
        alert(this.name +'价格'+ this.price+"元，"+this.hege);
    }
    //工厂函数
    function createCar(Sprice,Sname,Suse,Shege) {
        //创建对象
        var car = new Object();
        car.price = Sprice;
        car.name = Sname;
        car.use = Suse;
        car.hege = "合格";
        car.run = run1;
        return car;
    }
    //调用这个函数，调用一次创建一次（方法）
    var car1 = createCar( 10000, "宝马","跑","合格");

    car1.run();
</script>

</body>
</html>